package org.kordakus.shoot.gui.renderer;

import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.joda.time.DateTime;
import org.kordakus.shoot.gui.ShootGuiUtils;

public class DateTakenTableCellRenderer extends JLabel implements TableCellRenderer
{

	private static final long	serialVersionUID	= -4942898572395525595L;

	public DateTakenTableCellRenderer()
	{
		this.setOpaque(true);
		this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
		this.setFont(ShootGuiUtils.FONT_FORM);
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column)
	{
		ShootGuiUtils.setBackgroundColor(this, row, isSelected);

		if (value instanceof DateTime)
		{
			DateTime date = (DateTime) value;
			this.setFont(getFont().deriveFont(Font.PLAIN));
			this.setText(date.toString("YYYY-MM-dd HH:mm"));
		} else
		{
			this.setFont(getFont().deriveFont(Font.ITALIC));
			this.setText("Not found");
		}

		return this;
	}

}
